<template>
  <v-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'" label-width="120px">
      <el-row >
        <!-- <el-col :span="12">
            <el-form-item label="项目id" prop="project.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择项目id"
            labelName = 'projectName'
            labelValue = 'id'
            v-model = "inputForm.project.id"
            :limit="1"
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'projectName',
              label: '项目名称'
            }
            ]"
            :searchs="[
            {
              prop: 'projectName',
              label: '项目名称'
            }
            ]"
            :api="projectMainService">
          </GridSelect>
           </el-form-item>
        </el-col> -->
        <el-col :span="24">
            <el-form-item label="项目启动时间" prop="startDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.startDate"
                      type="datetime"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="项目结束时间" prop="endDate"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.endDate"
                      type="datetime"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="项目经理" prop="projectManager.id"
                :rules="[
                 ]">
                <user-select :limit='1' v-model="inputForm.projectManager.id"></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="会议纪要编号" prop="minutesNo"
                :rules="[
                 ]">
              <el-input v-model="inputForm.minutesNo" placeholder="请填写会议纪要编号"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <template #footer>    
        <span class="dialog-footer">
          <el-button @click="visible = false" icon="circle-close">关闭</el-button>
          <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button>
        </span>
    </template>    
  </v-dialog>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  import UserSelect from '@/components/userSelect'
  import projectMeetingService from '@/api/meeting/projectMeetingService'
  import projectMainService from '@/api/project/projectMainService'   
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        projectMainService: projectMainService,  
        inputForm: {
          id: '',
          project: {
            id: ''
          },
          startDate: '',
          endDate: '',
          projectManager: {
            id: ''
          },
          minutesNo: ''
        }
      }
    },
    components: {
      GridSelect,
      UserSelect
    },
    created () {
    },
    methods: {
      init (method, id) {
        this.method = method
       
        if (method === 'add') {
         this.inputForm.id = ''
          this.inputForm.project.id = id;
          this.title = `新建会议纪要`
        } else if (method === 'edit') {
          this.inputForm.id = id
          this.title = '修改会议纪要'
        } else if (method === 'view') {
          this.inputForm.id = id
          this.title = '查看会议纪要'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            projectMeetingService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            projectMeetingService.save(this.inputForm).then((data) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>

  
